package com.du.limiting.sentinel.controller;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.SphO;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.du.limiting.sentinel.model.Person;
import com.du.limiting.sentinel.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dujunguang
 * @date 2022/3/14 14:58
 * @description: TODO
 **/
@RestController()
@Slf4j
public class SentinelFlowControlTest {

//    @PostMapping("/flowControl")
//    @SentinelResource("flowControl")
//    public User flowControlQps(@RequestBody Person user) {
//        System.out.println("flowControlQps 流控Qps");
//        return user;
//    }

//    @PostMapping("/flowControl")
//    public User flowControlCode(@RequestBody Person user) {
//        Entry entry = null;
//        try {
//            entry = SphU.entry("flowControl", EntryType.IN, 1);
//            // Your logic here.
//        } catch (BlockException ex) {
//            throw new RuntimeException("限流异常");
//        } finally {
//            if (entry != null) {
//                entry.exit(1);
//            }
//        }
//        return user;
//    }
}
